package com.fywsy.fyweb.repository;

import com.fywsy.fyweb.entity.Category;
import com.fywsy.fyweb.entity.Qufu;
import jakarta.transaction.Transactional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Set;

@Repository
public interface QufuRepository extends JpaRepository<Qufu,Long> {

    List<Qufu> findAllByEnableAndGameId(boolean enable,long gameId);

    List<Qufu> findAllByGameId(long gameId);

    @Modifying
    @Transactional
    @Query(value = "DELETE FROM qufu WHERE game_id = :game_id AND id NOT IN :ids", nativeQuery = true)
    void deleteByGameIdAndIdNotIn(@Param("game_id") long gameId, @Param("ids") Set<Long> ids);

    @Modifying
    @Transactional
    @Query(value = "DELETE FROM qufu WHERE game_id = :game_id", nativeQuery = true)
    void deleteByGameId(@Param("game_id") long gameId);
}